import { createRouter, createWebHistory } from 'vue-router'
// 常量路由
export const constRouter = [
  {
    path: '/',
    name: 'home',
    component: () => import('../views/HomeView.vue')
  },
  {
    path: '/about',
    name: 'about',
    component: () => import('../views/AboutView.vue')
  }
]

// 动态路由或权限路由，基于用户权限动态去加载
export const asyncRouter = [
  
]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: constRouter,
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 }),
  // scrollBehavior(to, from, savedPosition) {
  //   if (savedPosition) {
  //     return savedPosition
  //   } else {
  //     return { top: 0 }
  //   }
  // },
})

// 全局路由守卫，检查用户是否登录，并重定向未登录用户到登录页面
// router.beforeEach((to, from, next) => {
  // const requiresAuth = to.matched.some(record => record.meta.requiresAuth);
  // const isAuthenticated = /* 检查用户是否登录 */ false;

  // if (requiresAuth && !isAuthenticated) {
  //   next('/login');
  // } else {
  //   next();
  // }
// });

export default router;